package com.atguigu.spzx.cloud.order.service.impl;

import com.atguigu.spzx.cloud.feign.api.UserFeignClient;
import com.atguigu.spzx.cloud.model.entity.Order;
import com.atguigu.spzx.cloud.model.entity.User;
import com.atguigu.spzx.cloud.order.mapper.OrderMapper;
import com.atguigu.spzx.cloud.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @Author yaya
 * @Create 2024/7/1 14:11
 * Description:
 */
@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderMapper orderMapper;


    @Autowired
    private UserFeignClient userFeignClient;

    @Override
    public Order findOrderByOrderId(Long orderId) {
        Order order = orderMapper.findOrderByOrderId(orderId);

        // 通过RestTemplate 调用网络接口
        // System.out.println(restTemplate.getForObject("https://www.baidu.com",String.class));
        // User user = restTemplate.getForObject("http://localhost:10100/api/user/findUserByUserId/1", User.class);
        // 使用nacos + loadBalanced 可以将固定的 ip + port 转换成被nacos管理的服务，
        // 使用loadBalance可以将这个服务正确的转发到对应端口
        // User user = restTemplate.getForObject("http://spzx-cloud-user/api/user/findUserByUserId/1", User.class);

        // 使用openFeign
        User user =userFeignClient.findUserByUserId(1l);

        order.setUser(user);

        return order;
    }

}
